 
class Printer {
public:
	vector<int> clockwisePrint(vector<vector<int> > mat, int n, int m) {
		// write code here
		// 左上角坐标
		int x1 = 0;
		int y1 = 0;
		// 右下角坐标
		int x2 = n - 1;
		int y2 = m - 1;
		vector<int> ret;
		while (x1 <= x2 && y1 <= y2)
		{
			// 第一行: x1, y1 ~ y2
			for (int i = y1; i <= y2; ++i)
			{
				ret.push_back(mat[x1][i]);
			}
			// 最后一列：x1 + 1 ~ x2, y2
			for (int i = x1 + 1; i <= x2; ++i)
			{
				ret.push_back(mat[i][y2]);
			}
			// 最后一行: x2, y2 - 1 ~ y1 --> x1 < x2
			if (x1 < x2)
			{
				for (int i = y2 - 1; i >= y1; --i)
				{
					ret.push_back(mat[x2][i]);
				}
			}
			// 第一列：x2 - 1 ~ x1 + 1, y1 --> y1 < y2
			if (y1 < y2)
			{
				for (int i = x2 - 1; i > x1; --i)
				{
					ret.push_back(mat[i][y1]);
				}
			}
			x1++;
			y1++;
			x2--;
			y2--;
		}
		return ret;
	}
};